package com.hyh.shiyanshiguanli.controller;

import com.hyh.shiyanshiguanli.constant.MessageConstant;
import com.hyh.shiyanshiguanli.domain.dto.*;
import com.hyh.shiyanshiguanli.domain.entity.Lib;
import com.hyh.shiyanshiguanli.domain.entity.LibInformation;
import com.hyh.shiyanshiguanli.domain.result.PageResult;
import com.hyh.shiyanshiguanli.domain.result.Result;
import com.hyh.shiyanshiguanli.domain.vo.LibVO;
import com.hyh.shiyanshiguanli.service.LibService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author hyh
 * @version 1.0
 */
@RestController
@Slf4j
@RequestMapping("/lib")
public class libController {

    @Autowired
    LibService libService;

    @GetMapping("/page")
    public Result<LibVO> page(LibDTO libDTO){
        log.info("实验室管理员查询{}",libDTO);

        LibVO libs = libService.page(libDTO);

        return Result.success(libs);
    }

    @PostMapping("/add")
    public Result addPublicInformation(@RequestBody LibAddDTO libAddDTO){
        log.info("添加libAddDTO{}",libAddDTO);
        libService.add(libAddDTO);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result<Lib> selectById(@PathVariable Integer id){
        log.info("根据id查询LibManager{}",id);
        Lib lib = libService.selectById(id);
        return Result.success(lib);
    }

    @PutMapping("/update")
    public Result updateById(@RequestBody LibUpdateDTO libUpdateDTO){
        log.info("更新实验室管理员数据id为{}",libUpdateDTO.getId());
        libService.updateById(libUpdateDTO);
        return Result.success();
    }


    @DeleteMapping("/deleteById")
    public Result deleteById(Integer id){
        log.info("删除id为{}的libManager",id);
        int delete = libService.deleteById(id);
        if (delete == MessageConstant.SUCCESS){
            return Result.success();
        }
        else{
            return Result.error("不能删除");
        }

    }
}
